package com.dearbinge.opentapi.content.moments;

import com.dearbinge.data.api.moments.CommentService;
import com.dearbinge.data.pojo.commodity.CommodityMessage;
import com.dearbinge.data.pojo.content.SendContent;
import com.dearbinge.data.pojo.moments.MessageComment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Api(description = "商友圈评论")
@RestController
@RequestMapping("/moments")
@EnableAutoConfiguration
public class CommentController extends WebMvcConfigurerAdapter {

    @Autowired
    CommentService commentService;

    @ApiOperation(value = "新增（id为空||id为0）/修改",notes = "新增（id为空||id为0）/修改")
    @RequestMapping(value = "/addOrUpdate",method = RequestMethod.POST)
    public String addOrUpdate(@RequestBody MessageComment messageComment){
        String dataStr = "系统异常";
        try{
            Integer dataCode = 0;
            if (messageComment.getCommentId() != null && messageComment.getCommentId()  != 0){
                dataCode = commentService.update(messageComment);
                if (dataCode > 0){
                    dataStr = "修改成功";
                }
            }else {
                dataCode = commentService.insert(messageComment);
                if (dataCode > 0){
                    dataStr = "添加成功";
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return dataStr;
    }
}
